package com.aotuman.ktcoroutineandroid.chapter.three

import com.aotuman.ktcoroutineandroid.chapter.two.MyContinuationImpl
import kotlin.coroutines.createCoroutine
import kotlin.coroutines.resume

suspend fun commonSuspendFun(): String {

    return "[hello world] "
}

suspend fun commonSuspendFun2(): String {

    return "[hello world 2]  "
}

suspend fun commonSuspendFun3(): String {

    return "[hello world 3]"
}

fun testFunGetContinuation() {

    // 1.构建suspend修饰的lambda函数
    val mySuspendLambda: suspend () -> String = {
        //返回一个字符串hello world
        val one = commonSuspendFun()
        //返回一个字符串hello world2
        val two = commonSuspendFun2()
        //返回一个字符串hello world3
        val three = commonSuspendFun3()
        one+two+three
    }

    // 2.创建协程：createCoroutine
    val myContinuationImpl = MyContinuationImpl()
    val createCoroutine = mySuspendLambda.createCoroutine(myContinuationImpl)

    // 3.启动协程 resume
    createCoroutine.resume(Unit)

}

fun main() {
    testFunGetContinuation()
}